/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package LoginStaffManager;
import java.sql.*;
import DBManager.DBConnection;
/**
 *
 * @author Alex
 */
public class LoginStaffManager {
     public boolean Log(String manager, String manpass)
    {
        boolean result = false;
        String type="";
        
        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn =  db.getConnection();
            
          
            PreparedStatement pstmt =  conn.prepareStatement("select * from manager where username=? and password=?");
            
            //append values for the parameters
            int i = 1;
            pstmt.setString(i++, manager);
            pstmt.setString(i++, manpass);
           
            //execute SQL statement
             ResultSet rs= pstmt.executeQuery();
            
           while(rs.next())
 {
result=true;
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}
            
           
        
        return result;
        
    }
     
      public String getID(String manager, String manpass)
    {
        
        
        String result= "";

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("SELECT usertype FROM haha where username = manager ");

            //append values for the parameters






            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=rs.getString(2);
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
      
       public String getInfo(String username, String needed)
    {
        String resultuser="";
        try{
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            String query = "select *  from user where username=\"" + username + "\"";
            Statement  stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery(query);

             while (rset.next())
             {

                    resultuser=rset.getString(needed);

             }

             }
        catch(SQLException ex){ 
            ex.printStackTrace();
        }
         
        return resultuser;
    }
}
